import config from 'config'
import httpFetch from 'share/httpFetch'
import errorMessage from 'share/errorMessage'

export default {

  //获取省份
  getAllProvinces() {
    return httpFetch.get(`${config.baseUrl}/api/areas/provinces`)
  },

  //获取城市
  getCities(code) {
    return httpFetch.get(`${config.baseUrl}/api/areas/cities/${code}`)
  },

  //获取所有区域
  getAreas(params) {
    return httpFetch.get(`${config.baseUrl}/api/areas/areas/by/name?`, params)
  },

  //获取收货地址
  getAddresses(companyOID, params){
    return httpFetch.get(`${config.baseUrl}/api/billing/contacts/company/${companyOID}`, params)
  },

  //修改收货地址
  editAddress(isNew, params){
    let method = isNew ? 'post' : 'put';
    return new Promise((resolve, reject) => {
      httpFetch[method](`${config.baseUrl}/api/billing/contacts`, params).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

}
